<?php
namespace app\admin\controller;

use app\common\AdminController;
use app\admin\model\System as SM;
use think\facade\Cache;

/**
 * Class Config  配置管理
 * @package app\admin\controller
 * @author fuwei
 * @time 2020-01-06
 */
class Config extends AdminController
{
    /**
     * 系统配置
     * @return \think\response\View
     */
    public function system()
    {
        $system = SM::lists();
        return view('', compact('system'));
    }

    /**
     * [setting 更新设置项目]
     * @return [type] [description]
     */
    public function setting()
    {
        $input      = $this->request->param();
        $conf_type  = isset($input['conf_type']) ? (int) $input['conf_type'] : 1;
        unset($input['conf_type']);
        if (count($input) > 0) {
            foreach( $input as $key => $inp) {
                SM::updateItem($key, $inp, $conf_type);
            }
        }
        return $this->successRender();
    }

    /**
     * 缓存清理
     * @return array|mixed|\think\response\View
     */
    public function cache()
    {
        $cache_dir = $this->app->getRuntimePath() . '/../cache/';
        deldir($cache_dir);
        return view('');
    }
}
